/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.impl;

/**
 *
 * @author administrator
 */
import java.util.List;

import dao.IDao;
import service.IService;
import debug.Debugger;

public abstract class ServiceImpl<T> implements IService<T> {

    protected IDao<T> dao;

    public IDao<T> getDao() {
        return dao;
    }

    public void setDao(IDao<T> dao) {
        Debugger.checkPoint((dao != null), "dao hooked in ServiceImpl");
        this.dao = dao;
    }

    public T find(Class<T> clazz, int id) {
        return dao.find(clazz, id);
    }

    public int getTotalCount(String hql, Object... params) {
        return dao.getTotalCount(hql, params);
    }

    public void save(T baseBean) {
        dao.save(baseBean);
    }

    public void create(T baseBean) {
        dao.create(baseBean);
    }

    public void delete(T baseBean) {
        dao.delete(baseBean);
    }

    public List<T> list(String hql) {
        return dao.list(hql);
    }

    public List<T> list(String hql, int firstResult, int maxSize,
            Object... params) {
        return dao.list(hql, firstResult, maxSize, params);
    }

    /**
     * @author: Yu
     * @param hql
     * @return
     * I defined this method to get the total number of the threads
     */
    //public int countAll(String hql){
        //return (Integer) dao.list(hql).get(0);
    //}
}
